<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        input{
            width: 300px;
            height: 30px;
        }
        button{
            width: 50px;
            height: 30px;
        }
    </style>
</head>
<body>
请输入数字：<input type="text">
<button>搜索</button>
<script>
    var inp=document.getElementsByTagName("input")[0];
    var btn=document.getElementsByTagName("button")[0];
    var bool=false;
    btn.onclick=function(){
        var str=inp.value;
        for(var i=0;i<str.length;i++){
            if(str.charCodeAt(i)<47||str.charCodeAt(i)>58){
                alert("输入中存在非数字！！！");
                bool=true;
                break;
            }
        }
        if(i===str.length){
            alert("输入成功！！");
        }
    }

</script>
</body>
</html>